route.ts 942 B

1234567891011121314151617181920
  1. import { NextRequest, NextResponse } from 'next/server';
  2. import { ResultDto } from '@/types/response/common';
  3. import { fetchJson } from '@/lib/utils/server';
  4. export async function GET(request: NextRequest, { params }: { params: Promise<{ path: string[] }> }) {
  5. const { path } = await params;
  6. const endpoint = `/api/payment/${path.join('/')}`;
  7. const url = new URL(request.url);
  8. const res: ResultDto = await fetchJson(`${endpoint}${url.search}`, { method: 'GET' });
  9. return NextResponse.json(res);
  10. }
  11. export async function POST(request: NextRequest, { params }: { params: Promise<{ path: string[] }> }) {
  12. const { path } = await params;
  13. const endpoint = `/api/payment/${path.join('/')}`;
  14. const jsonBody = await request.json();
  15. console.log('[Payment Route] POST', endpoint, JSON.stringify(jsonBody));
  16. const res: ResultDto = await fetchJson(endpoint, { method: 'POST', body: JSON.stringify(jsonBody) });
  17. return NextResponse.json(res);
  18. }